package com.xxl.job.admin.controller.interceptor;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * info:
 * author: kevin
 * time:2018/4/1 9:42
 */
@Configuration
@ConfigurationProperties(prefix = "web.white")
public class WhiteDomainConfig {
    private Set<String> domainSet  = new HashSet<>();

    private List<String> domains = new ArrayList<>();

    public List<String> getDomains() {
        return domains;
    }

    public void setDomains(List<String> domains) {
        this.domains = domains;

    }

    public boolean hasAuth(String domain){
        if(this.domainSet.size() == 0){
            for (String domainInfo : this.domains) {
                domainSet.add(domainInfo);
            }
        }
        return this.domainSet.contains(domain);
    }
}
